#!/bin/sh
. /etc/nap.conf

if [[ -f "$1" ]]
then
	sharename=`echo "$1" | sed -e 's#/# #g' -e 's/  */ /g'`
	link=$napshared/links/$sharename
	if [ -e "$link" ]
	then
		rm "$link"
	fi
	ln -s "$1" "$napshared/links/$sharename"
	if [[ $? = 0 ]]
	then
		echo shared 1 item
	fi
else 
	echo "$1" | egrep '^peer|^http' > /dev/null 2>&1
	if [[ $? = 0 ]]
	then
		echo "unable to share over a network"
		return
	fi
	IFS=$(echo -en "\n\b")
	list=`getmusiclist "$1"`
	for item in $list
	do
		sharename=`echo "$item" | sed -e 's#/# #g' -e 's/  */ /g'`
		link=$napshared/links/$sharename
		if [ -e "$link" ]
		then
			rm "$link"
		fi
		ln -s "$item" "$link"
	done
	echo shared `echo "$list" | wc -l` items
fi
	
